
import React,{
    useReducer
} from "react";



const TestUseReducer = ()=>{
    const reduce = (state, action)=>{
        switch (action.type) {
            case "add":
                return state + 1;
            case 'cut':
                return state - 1;
            default:
                return state;
        }
    }

    const init = ()=>{
        return 66;
    }
    const [state, dispatch] = useReducer(reduce,0,init)
    return (
        <>
            {state}
            <br/>
            <button onClick={()=>dispatch({type:'add'})}>+</button>
            <br/>
            <button onClick={()=>dispatch({type:'cut'})}>-</button>

        </>
    )
}

export default TestUseReducer;